package top.fyukina.fymil.elements;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;
import top.fyukina.fymil.Registry;

public class Program {
    private final String name;
    private final CmdBlock main;
    public Program(Document document, String fileName) {
        Element root = document.getRootElement();
        Attribute name = root.attribute("name");
        this.name = name == null ? fileName : name.getName();
        main = new CmdBlock(root.element("main"), new VarDomainStack());
    }
    public void run(ProgramPack pack, Registry registry) {
        Environment env = new Environment(
                pack, this, new VarDomainStack(), registry
        );
        main.execute(env);
    }
    public String getName() {
        return name;
    }
}